package com.atguigu.spring.ioc.bean;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import lombok.Data;
import lombok.ToString;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;

@ToString
@Data
public class User implements InitializingBean, DisposableBean {
    private String name;
    private int age;

    private Car car;

    @Autowired
    public void setCar(Car car) {
        System.out.println("自动注入,属性值: " + car);
        this.car = car;
    }

    public User() {
        System.out.println("User constructor");
    }

    public void initUser() {
        System.out.println("User init");
    }

    public void destoryUser() {
        System.out.println("User destory");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("User destroy listener");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("User after properties set");
    }

    @PostConstruct
    public void postConstruct() {
        System.out.println("User post construct");
    }

    @PreDestroy
    public void preDestory() throws Exception {
        System.out.println("User pre destroy");
    }
}
